"use strict";
cc._RF.push(module, 'b6c79S98MJAU6hn1MQuW4II', 'WeChatFileSystemManager');
// src/WeChatFileSystemManager.js

"use strict";

var n = module.exports = {};
var t = module;
console.assert(true), t.exports = {
  init: function init(e, t) {
    this.fileSystemManager = wx.getFileSystemManager(), this.rootPath = "" + wx.env.USER_DATA_PATH, this.urlRoot = e, this.gameName = t, console.log(this.gameName);
  },
  getFileName: function getFileName(e) {
    for (var t = e.substring(e.indexOf(this.urlRoot), e.length); -1 != t.indexOf("/");) {
      var n = t.indexOf("/");
      t = t.substring(0, n) + "-" + t.substring(n + 1, t.length);
    }

    return t;
  },
  getFile: function getFile(e) {
    var t = this.getFileName(e.url),
        n = this.rootPath + "/" + t,
        i = this;
    this.fileSystemManager.stat({
      path: n,
      success: function success(i) {
        i.stats.isDirectory(), i.stats.isFile() && (console.log("这是文件： " + t), e.success(n));
      },
      fail: function fail(o) {
        console.log(t + "文件不存在，下载"), console.log(e.url + "?" + i.gameName), wx.downloadFile({
          url: e.url + "?" + i.gameName,
          success: function success(t) {
            console.log("下载成功"), wx.saveFile({
              tempFilePath: t.tempFilePath,
              filePath: n,
              success: function success(t) {
                console.log("保存到本地"), e.success(n);
              },
              fail: function fail(t) {
                console.log(t), e.fail();
              }
            });
          },
          fail: function fail(t) {
            console.log(t), e.fail();
          }
        });
      }
    });
  },
  removeFile: function removeFile(e) {
    var t = this.getFileName(e.url),
        n = this.rootPath + "/" + t,
        i = this;
    this.fileSystemManager.stat({
      path: n,
      success: function success(t) {
        i.fileSystemManager.unlink({
          filePath: n,
          success: function success() {
            e.success();
          },
          fail: function fail(e) {
            console.log(e);
          }
        });
      },
      fail: function fail(t) {
        console.log("本地不存在"), e.success();
      }
    });
  },
  showFile: function showFile() {
    this.fileSystemManager.readdir({
      dirPath: "" + wx.env.USER_DATA_PATH,
      success: function success(e) {
        console.log(e);
      },
      fail: function fail() {}
    });
  }
};

cc._RF.pop();